#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
以'w'模式写入文件时，如果文件已存在，会直接覆盖（相当于删掉后新写入一个文件）。如果我们希望追加到文件末尾怎么办？可以传入'a'以追加（append）模式写入。
'''
from datetime import datetime

with open('./test.txt', 'w', encoding='utf-8') as f:
    f.write('今天是 ')
    f.write(datetime.now().strftime('%Y-%m-%d'))
    
with open('./test.txt', 'a', encoding='utf-8') as f:
    f.write('\n jack')
    
with open('./test.txt', 'r', encoding='utf-8', errors='ignore') as f:
    s = f.read()
    print('open for read...')
    print(s)

with open('./test.txt', 'rb') as f:
    s = f.read()
    print('open as binary for read...')
    print(s)
with open('./test1.txt', 'rb') as f:
    s = f.read()
    print('open as binary for read...')
    print(s)
